package com.itheima.web.controller;

import cn.hutool.core.util.StrUtil;
import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 请不要叫我高司令
 * @Date 2022/3/24 18:40
 * @Version 1.0
 */

@RestController
public class UserController {


    @Autowired
    private UserManager userManager;

    // 用户列表
    @GetMapping("/manage/users")
    public ResponseEntity users(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize

    ) {

        return userManager.users(pageNum, pageSize);

    }

    // 用户详情
    @GetMapping("/manage/users/{userId}")
    public ResponseEntity findUserInfoById(@PathVariable Long userId) {

        return userManager.findUserInfoById(userId);

    }


    // 动态查询
    @GetMapping("/manage/messages")
    public ResponseEntity messages(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "uid", required = false) Long userId,
            String state) {

        //处理动态状体
        Integer stateInt = null;
        if (StrUtil.isNotEmpty(state) && !StrUtil.equals(state, "''")) {

            stateInt = Integer.parseInt(state);

        }
        return userManager.messages(userId, stateInt, pageNum, pageSize);

    }


    // 动态详情
    @GetMapping("/manage/messages/{publishId}")
    public ResponseEntity findMovementVoById(@PathVariable String publishId){
        // 调用manager
        return userManager.findMovementVoById(publishId);
    }

    //评论列表
    @GetMapping("/manage/messages/comments")
    public ResponseEntity findCommentVoByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "messageID") String publishId
    ) {

        return userManager.findCommentVoByPage(publishId,pageNum,pageSize);


    }


    //小视频查询
    @GetMapping("/manage/videos")
    public ResponseEntity findVideoVoById(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "uid") Long userId
    ) {

        return userManager.findVideoVoById(userId, pageNum, pageSize);

    }



}
